'use strict';

module.exports = app => {
  const { ENUM, INTEGER, STRING, TEXT } = app.Sequelize;
  // 文章类
  const Article = app.model.define('article', {
    // 标题
    title: { type: STRING, allowNull: false },
    // 内容
    content: { type: TEXT('medium'), allowNull: false },
    // 类别
    category: { type: STRING, allowNull: false },
    // 状态
    status: {
      type: ENUM,
      values: [ 'draft', 'published' ],
      allowNull: false,
      defaultValue: 'draft',
    },
    // 排序
    order: INTEGER,
  });

  Article.associate = function() {
    // 文章封面图片文件
    Article.belongsTo(app.model.File, { as: 'image' });
  };

  return Article;
};
